<template>
  <ul>
    <li v-for="(item,index) in getListData" @click="setId(item)">
      <a>
        <img :src="item.img" alt="">
        <p class="pr">
          <img v-if="!item.over" class="middle pa" :src="imgs.time" alt="">
          <span v-if="!item.over">离报名结束仅剩<span v-for="(time,index1) in item.time" :class="{'color-gold':index1 % 2==0}">{{time}}</span></span>
          <span :class="{'fr':true,'disabled':item.over,'play':!item.over}">{{item.over?"已经结束":"我要报名"}}</span>
        </p>
        <p class="pr">
          <img class="middle pa" :src="imgs.sign" alt="">
          <span class="fontsize12">{{item.people}}人已报名</span>
        </p>
      </a>
    </li>
  </ul>
</template>
<script>
export default {
  props: ["data"],
  components: {},
  name: "",
  data() {
    return {
      imgs: {
        sign: require("../../../../assets/img/hpmepage/discount/sign.png"),
        time: require("../../../../assets/img/hpmepage/discount/time.png")
      },
      list:[]
    };
  },
  computed: {
    getListData() {
      this.list=JSON.parse(JSON.stringify(this.data))
      // console.log(this.list)
      this.list.forEach(ele=>{
        if(ele.time){
          ele.time=this.formatTime(ele.time)
        }
      })
      return this.list
    }
  },
  methods: {
    formatTime(val) {
      var day = Math.floor(val / (3600 * 24));
      var hour = Math.floor((val % (3600 * 24)) / 3600);
      var minute = Math.floor(((val % (3600 * 24)) % 3600) / 60);
      var second = Math.floor(((val % (3600 * 24)) % 3600) % 60);
      return [day,"天",hour,"小时",minute,"分",second,"秒"]
    },

    // 存储id
    setId(item){
      if(!item.over){
        sessionStorage.setItem("detailId",item.id)
        this.$router.push("/discount/detail/"+item.id)
      }else{
        this.$store.state.dialogs.alert.content="活动已经结束"
        // this.$store.state.dialogs.alert.OK=()=>{this.$router.go(-1)}
        this.$store.state.dialogs.alert.show=true
      }
    }
  },
  created() {
    
  },
};
</script>
<style lang="scss" scoped>

ul {
  background-color: #f2f2f2;
  padding-bottom: 0.1px;

  li {
    background-color: #fff;
    
    a {
      display: inline-block;
      height: 100%;
      width: calc(100% - 30px);
      margin: 15px;
      margin-top: 0;
      padding-bottom: 10px;
      box-sizing: border-box;
      border: 1px solid #f2f2f2;

      >img {
        width: 100%;
        min-height: 150px;
      }
    }
    a:active {
      opacity: 0.8;
    }
    
    p {
      margin-top: 5px;
      color: #666;
      text-indent: 28px;
    

      img {
        width: 16px;
        height: 16px;
        left: 8px;
      }

      span {
        line-height: 18px;
      }
    }
    p:nth-child(1){
      margin-top: 10px;
    }
  }
  li:nth-child(1){
    padding-top: 15px;
  }
  .color-gold{
    padding: 0 1px;
  }
  .disabled{
    width: 60px;
    text-indent: 0;
    margin-right: 5px;
    text-align: center;
    border-radius: 2px;
    background-color: #ccc;
    font-size: 14px;
  }
  .play{
    width: 60px;
    right: 8px;
    text-indent: 0;
    text-align: center;
    background: linear-gradient(left bottom,#FF6613,#FFA200);
    background: -webkit-gradient(linear, left bottom, right top, from(#FF6613), to(#FFA200));
    color: #fff;
    border-radius: 2px;
    padding: 2px 3px;
    position: absolute;
  }
}
</style>